package com.lh.disruptor;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: linghao
 * @since: 2025/5/24
 */
public class DisruptorThreadFactory implements ThreadFactory {

    private final AtomicInteger index = new AtomicInteger(1);
    private String threadName;

    public DisruptorThreadFactory(String name) {
        this.threadName = name;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(null, r, threadName + "-" + index.getAndIncrement());
        thread.setDaemon(true);
        return thread;
    }
}
